package com.skyline.search.client;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;
import java.rmi.Naming;
import java.util.Properties;

import com.skyline.search.config.Config;
import com.skyline.search.index.IndexProxy;
import com.skyline.search.search.SearchProxy;

/*暂时没用*/
public class Client {
	private static String properties = "com/skyline/search/config/config.properties";
	private static IndexProxy indexproxy;
	private static SearchProxy searchproxy;

	public static void setProperties(String properties) {
		Client.properties = properties;
	}

	public static void config() {
		URL sqlDir = Config.class.getClassLoader().getResource(properties);
		File file = new File(sqlDir.getPath().replace("%20", " "));
		InputStream is;
		try {
			is = new FileInputStream(file);
			Properties ps = new Properties();
			ps.load(is);
			is.close();
			String serverIP = (String) ps.get("server");
			indexproxy = (IndexProxy) Naming.lookup("rmi://" + serverIP
					+ "/indexproxy");
			searchproxy = (SearchProxy) Naming.lookup("rmi://" + serverIP
					+ "/searchproxy");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static IndexProxy getIndexproxy() {
		return indexproxy;
	}

	public static SearchProxy getSearchproxy() {
		return searchproxy;
	}

}
